package mobel

import (
	"gorm.io/gorm"
	"message-queue_0826/global"
	"time"
)

type Contact struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:联系人ID;primaryKey;not null;" form:"id" json:"id"` // 联系人ID
	Name      string         `gorm:"column:name;type:varchar(30);comment:备注;not null;" form:"name" json:"name"`          // 备注
	Mobile    string         `gorm:"column:mobile;type:char(11);comment:联系方式;not null;" form:"mobile" json:"mobile"`     // 联系方式
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (c *Contact) TableName() string {
	return "contact"
}

// 添加
func (c *Contact) AddContact() error {
	return global.DB.Create(&c).Error
}

// 查找
func (c *Contact) GetContact() error {
	return global.DB.Where("mobile = ?", c.Mobile).Find(&c).Error
}

// 查找
func (c *Contact) FindContact() error {
	return global.DB.Where("id = ?", c.Id).Find(&c).Error
}
